package org.unikn.dbvis.tools;

import processing.core.*;

class WorldMap  {
  
  int x, y, w, h;
  PShape raster;
  PApplet p;
  
  WorldMap(PApplet p, int w, int h) {
	  this(p,0, 0, w, h);

  }
  
  WorldMap(PApplet p, int x, int y, int w, int h) {
	  this.p = p;
    if (h >= w/2) {
      this.w = w;
      this.h = w/2;
      this.x = x;
      this.y = (h - this.h)/2;
    } else {
      this.h = h;
      this.w = 2*h;
      this.x = (w - this.w)/2;
      this.y = y;
    }
    raster = p.loadShape("../etc/worldmap.svg");
    
  }
  void drawBackground(int zoom) {
//      p.shape(this.raster, x, y, w, h);
//  	PApplet eins = new PApplet();
//  	float t = w / h;
//  	float z = zoom != 1 ? (float) (0.5 * zoom) : (float) (1.0 * zoom);
//    raster = eins.loadImage("../etc/world_longlatwgs84.png");
//    if(z == 1) p.image(raster, x, y);
//    
//    int tmp = (int) (h - z * 10);
//    int yy = p.mouseY - tmp < 0 ? 0 + tmp : tmp;
//    yy = yy > h ? h - tmp : yy;
//    
//    tmp = (int) (w -z * 10);
//    int xx = p.mouseX - tmp < 0 ? 0 + tmp : tmp;
//    xx = xx > w ? w - tmp : xx;
//    
//    if(z != 1) {
//	    raster = p.get((int) (x + z * 5), (int) (y + z * 5), (int) (w - z * 10), (int) (t*(h - z * 10)));
//	    p.image(raster, x, y, w, h);
//    }
    p.shape(this.raster, x, y, w, h);
	}
  
  public final Point getPoint(final float phi, final float lambda, final int zoom) {
    return new Point(
      x + ((180+lambda)/360)*w,
      y + h - ((90+phi)/180)*h
    );
  }
  
}

final class Point  {
	public double x, y;
  Point(final double x, final double y) {this.x = x; this.y = y; }
}


